package com.tt.jshb.bill.detail;

import com.alibaba.fastjson.JSON;
import com.hzecool.common.utils.SPUtils;
import com.hzecool.core.base.TBasePresenter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.tt.jshb.app.Constants;
import com.tt.jshb.app.ServerUrls;
import com.tt.jshb.bean.DetailBean;
import com.tt.jshb.bean.PayBean;

import okhttp3.Call;
import okhttp3.Response;

/**
 * @author tutu
 * @time 2018/7/26
 */

public class DetailPresenter extends TBasePresenter<IDetailView> {
    @Override
    protected void start() {

    }

    public void getDetail(String id){
        OkGo.post(ServerUrls.ROUTER + "app/recyclingRecordsById.htm")
                .params("tokens", SPUtils.getString(Constants.SP_TOKENDS))
                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            DetailBean bean = JSON.parseObject(s, DetailBean.class);
                            if (bean.getCode() == 0) {
                                getView().onLoadDetail(bean);
                            } else {
                                getView().onLoadError(bean.getMsg());
                            }
                        } catch (Exception e) {
                        }
                    }
                });
    }


    public void payInfo(String id,String zf) {
        OkGo.post(ServerUrls.ROUTER + "app/recyclingRecordsByHkPay.htm")
                .params("tokens", SPUtils.getString(Constants.SP_TOKENDS))
                .params("id",id)
                .params("zf",zf)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            PayBean bean = JSON.parseObject(s, PayBean.class);
                            if (bean.getCode() == 0) {
                                getView().onPayResult(bean);
                            } else {
                                getView().onLoadError(bean.getMsg());
                            }
                        } catch (Exception e) {
                        }
                    }
                });
    }
}
